﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.Linq;
using System.Linq;
using System.Transactions;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace aspnet2
    {
    public partial class _Default : System.Web.UI.Page
        {
        DataClasses1DataContext db = new DataClasses1DataContext();
        protected void Page_Load(object sender, EventArgs e)
            {


            if (!IsPostBack) {
            this.ErrorInfo.Text = null;
                
                }
            }

        protected void Button1_Click(object sender, EventArgs e)
            {
            try
                {
                Membership.CreateUser(this.UserName.Text, this.Password.Text);
                Roles.AddUserToRole(this.UserName.Text, "User");
               


                using (TransactionScope ts = new TransactionScope())
                    {
                    PrinterUser us = new PrinterUser();
                    us.UserName = this.UserName.Text;
                    us.ProvinceID = db.Province.Where(c => c.ProvinceName == this.DropDownList1.SelectedValue).Select(c => c.ID).First();
                    us.UserType = 0;
                    us.UserStarDegree = 0;
                    us.Point = 0;
                    
                    db.PrinterUser.InsertOnSubmit(us);
                    db.SubmitChanges();
                    ts.Complete();
                    }
                  Response.Redirect("~/Login.aspx");


                }
            catch (MembershipCreateUserException ex)
                {
                this.ErrorInfo.Text = ex.StatusCode + ex.Message;
                }
            }


        }
    }
